const fs = require('fs')

//读数据
const usersString = fs.readFileSync('./db/user.json').toString()
const usersArray = JSON.parse(usersString)  //把字符串变成数组
console.log(usersArray)
console.log(typeof usersArray)  //返回usersString的数据类型
console.log(usersArray instanceof Array)  //是数组则返回true

//写数据
const user3 = {id:3,name:"小红",password:'zzz'}
usersArray.push(user3)
const string = JSON.stringify(usersArray)  //把js对象编程字符串
fs.writeFileSync('./db/user.json',string)